import Vue from 'vue'
const vm = new Vue({})
import { API_ROOT } from '../util/config'
import axios from 'axios'
import router from '../router'
import {
  setStore,
  getStore,
  removeStore
} from '../util/util';

export default {

  login({
    commit
  }, params) {
  	console.log(params)
  		return axios.get(API_ROOT+'action=verifyTheTeacher',{params}).then(function(out){
  			if(out.data.data.key==0){
  				router.replace('/notOrder')
  			}else{
  				var obj=out.data.data.teacherdata;
  			obj.id=obj.uid;
  			obj.className=out.data.data.classList[0].classname
  			obj.classList=out.data.data.classList  		
  			obj.courseList=out.data.data.courseList
      		removeStore('classGroup')
       	 	commit('USER_LOGIN', obj)        
        	router.push('/tiku/1')
  			}
  			
        	
  		})
  },
  weChatLogin({
    commit
  }, payload) {
    return axios.post(API_ROOT + '/iweb/wxlogin/login', payload).then(response => {
      let res = response.data;
      console.log(response)
      if (res.status == 0) {
        console.log(res.data)
        router.push('/register')
        setStore('weChat', res.data)
      }
      if (res.status == 1) {
        vm.$message.success('登录成功');
        commit('USER_LOGIN', res.data)
        //      router.push('/user/userinfo')
        window.open("http://web.li-shang-bin.com/#/user/userinfo", "_self");
        console.log(window.location.href)
      }
    })
  },

  userlogout({
    commit
  }) {
    commit('USER_LOGOUT');
    router.push({
      path: '/login'
    });
  },


}